extension CVImageBuffer {
+ static let sharedContext = CIContext()
+
var cgImage: CGImage? {
let ciImage = CIImage(cvImageBuffer: self)
- let context = CIContext()
- return context.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: CVPixelBufferGetWidth(self), height: CVPixelBufferGetHeight(self)))
+ return CVImageBuffer.sharedContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: CVPixelBufferGetWidth(self), height: CVPixelBufferGetHeight(self)))
}
}